package com.ruoyi.storage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.DeliveryDetail;
import com.ruoyi.storage.service.IDeliveryDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货品配送Controller
 * 
 * @author 庞一恺
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/storage/deliveryDetail")
public class DeliveryDetailController extends BaseController
{
    @Autowired
    private IDeliveryDetailService deliveryDetailService;

    /**
     * 查询货品配送列表
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryDetail deliveryDetail)
    {
        startPage();
        List<DeliveryDetail> list = deliveryDetailService.selectDeliveryDetailList(deliveryDetail);
        return getDataTable(list);
    }

    /**
     * 导出货品配送列表
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:export')")
    @Log(title = "货品配送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryDetail deliveryDetail)
    {
        List<DeliveryDetail> list = deliveryDetailService.selectDeliveryDetailList(deliveryDetail);
        ExcelUtil<DeliveryDetail> util = new ExcelUtil<DeliveryDetail>(DeliveryDetail.class);
        util.exportExcel(response, list, "货品配送数据");
    }

    /**
     * 获取货品配送详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:query')")
    @GetMapping(value = "/{deliveryDetailId}")
    public AjaxResult getInfo(@PathVariable("deliveryDetailId") String deliveryDetailId)
    {
        return success(deliveryDetailService.selectDeliveryDetailByDeliveryDetailId(deliveryDetailId));
    }

    /**
     * 新增货品配送
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:add')")
    @Log(title = "货品配送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryDetail deliveryDetail)
    {
        return toAjax(deliveryDetailService.insertDeliveryDetail(deliveryDetail));
    }

    /**
     * 修改货品配送
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:edit')")
    @Log(title = "货品配送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryDetail deliveryDetail)
    {
        return toAjax(deliveryDetailService.updateDeliveryDetail(deliveryDetail));
    }

    /**
     * 处理到货货品配送
     */
    @PreAuthorize("@ss.hasPermi('storage:deliveryDetail:remove')")
    @Log(title = "货品配送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deliveryDetailIds}")
    public AjaxResult remove(@PathVariable String[] deliveryDetailIds)
    {
        return toAjax(deliveryDetailService.arriveDeliveryDetailByDeliveryDetailIds(deliveryDetailIds));
    }
}
